<?php
/**
 * oscshop2 B2C电子商务系统
 *
 * ==========================================================================
 * @link      http://www.oscshop.cn/
 * @copyright Copyright (c) 2015-2017 oscshop.cn. 
 * @license   http://www.oscshop.cn/license.html License
 * ==========================================================================
 *
 * @author    李梓钿
 *
 */
 
namespace osc\mobile\controller;
use think\Db;
use think\Session;
class Share extends MobileBase
{
	protected function _initialize(){
		parent::_initialize();						
		define('UID',is_login());	
		//手机版
		if(!UID){		
			$this->redirect('login/login');					
		}

		if (!Session::has("username")) {

            $this->redirect('login/login');

        }		
	}

	function index()
	{

		$username = session('username');
		$user =  Db::name('member')->where('sharemobile',$username)->select();
		$count = Db::name('member')->where(['sharemobile'=>$username,'user_state'=>['>=',1]])->count();
		//var_dump($user);
		//ie;

		$this->assign('user',$user);	
		$this->assign('count',$count);
		//var_dump($user);
		$this->assign('top_title','我的分享');
		$this->assign('SEO',['title'=>'我的分享-'.config('SITE_TITLE')]);
		return $this->fetch();
		
	}

	function share1user()
	{

		$username = session('username');
		$user =  Db::name('member')->where('sharemobile',$username)->select();

		$this->assign('user',$user);	
		//var_dump($user);		
		$this->assign('top_title','我的一级分享');
		$this->assign('SEO',['title'=>'我的一级分享-'.config('SITE_TITLE')]);
		return $this->fetch();
	}
	
	function share2user()
	{
		$data=input('get.'); 
		$username = session('username');
		var_dump($data);
		if(!$data)
		{
			$this->redirect('share/index');
		}
		//判断用户是否是该用户下推荐用户
		$user1 =  Db::name('member')->where('username',$data['id'])->find();
		if(!$user1)
		{
			$this->redirect('share/index');
		}
		if($user1['sharemobile']!=$username)
		{
			$this->redirect('share/index');
		}

		$user =  Db::name('member')->field('username')->where('sharemobile',$username)->select();
		//$data=array();

		$user3 = Db::name('member')->where('sharemobile',$data['id'])->select();

		//var_dump($user);
		if($user)
		{
			for ($i=0; $i<sizeof($user); $i++) 
			{
				$data[$i] = $user[$i]['username'];
			}
		}
		
		//var_dump($data);

        //$user2 = Db::name('member')->where('sharemobile','IN',$data)->select();

		/*
        $user2 = Db::name('member')
			->where('sharemobile','IN',function($query){
    		$query->name('member')->where('sharemobile',$username)->field('username');
			})->select();
			*/


		$this->assign('user',$user3);	
		$this->assign('user1',$user1);
		$this->assign('top_title','我的分享');
		$this->assign('SEO',['title'=>'我的分享-'.config('SITE_TITLE')]);
		return $this->fetch();
	}
	

}
